<?php

function encodeFilename($filename)
{
    return str_replace(" ", "%20", $filename);
}

function showMetadata($context, $ctype, $filename, $ext, $md)
{
    if ($md)
    {
        $fn = 'format'.ucfirst($ctype);
        $link = false;
        $res = $fn($context, $md, $link);
    }

    if (!$link)
    {
        $end = strripos($filename, ".$ext");
        if ($end === false) 
            $nfilename = $filename;
        else
            $nfilename = trim(substr($filename, 0, $end));
        
        if (!strchr($nfilename, " ")) $nfilename = str_replace(array("_", "."), " ", $nfilename);
        $res = '<tr><td>'.$context->translate("Name").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($nfilename)."'>".htmlentities($nfilename, ENT_QUOTES, "UTF-8")."</a></td></tr>$res";
    }

    if ($ext=="torrent")
    {
        if ($files = $md["torrent:filepaths"]){
            $l=2;
            while ($more = $md["torrent:filepaths$l"]) { $files .= " ".$more; $l++;}
            
            $names = explode("//", $files);

            $sizes = $md["torrent:filesizes"];
            if ($sizes)
            {
                $l=2;
                while ($more = $md["torrent:filesizes$l"]) { $sizes .= " ".$more; $l++;}
                $sizes = explode(" ", $sizes);
            }
            
            for ($i=0; $i<count($names); $i++)
            {
                if ($sizes[$i]) $size = " (".formatSize($sizes[$i]).")"; else $size = "";
                $extra .= "<li>{$names[$i]}$size</li>";
            }
            $extra = "<div class='download_file_torrent_files'>Torrent&nbsp;files: <ul>$extra</ul></div>";
        }
    }
    echo "<table>$res</table>$extra";
}

function formatLength($text)
{
    $secs = (int)$text;
    $mins = 0;
    if ($secs>59) {
        $mins = $secs/60;
        $secs = $secs%60;
        if ($mins>59) {
            $hours = $mins/60;
            $mins = $mins%60;
        }
    }
    if ($hours)
        return sprintf("%d:%02d:%02d", $hours, $mins, $secs);
    else
        return sprintf("%d:%02d", $mins, $secs);
}

function format($context, $md, &$link)
{
    return "";
}

function formatAudio($context, $md, &$link)
{
    $res = "";
    if ($title = $md["audio:title"]){
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a>";
        $link = true;
        if ($len = $md["audio:seconds"])
            $res .= "&nbsp;(".formatLength($len).')';
        $res .= '</td></tr>';
    }
    if ($artist = $md["audio:artist"]){
        $link = true;
        $res .= '<tr><td>'.$context->translate("Artist").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($artist)."'>".htmlentities($artist, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }
   
    if ($album = $md["audio:album"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Album").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($album)."'>".htmlentities($album, ENT_QUOTES, "UTF-8")."</a>";
        if (($year = $md["audio:year"]) && is_numeric($year) && $year>1901 && $year<2100)
            $res .= "&nbsp;($year)";
        $res .= '</td></tr>';
    }
     if ($track = $md["audio:track"]) $res .=  "<tr><td>".$context->translate("Track").":</td><td>$track</td></tr>";
    if ($genre = $md["audio:genre"]) $res .=  "<tr><td>".$context->translate("Genre").":</td><td>$genre</td></tr>";
    if ($bitrate = $md["audio:bitrate"]) $res .= "<tr><td>". $context->translate("Quality").":</td><td>$bitrate&nbsp;kbit/s.&nbsp;". $md["audio:soundtype"]."</td></tr>";
    return $res;
}

function formatDocument($context, $md, &$link)
{
    $res = "";

    if  ( ($title = $md["book:title"]) || ($title = $md["document:title"]) ){
        $link = true;
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }
    if ( ($author = $md["book:author"]) || ($author = $md["document:author"]) ) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Author").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($author)."'>".htmlentities($author, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }
    if ($format = $md["document:format"]) {
        $res .= '<tr><td>'.$context->translate("Format").":</td><td>$format";
        if ($fversion = $md["document:formatversion"])
            $res .= "&nbsp;v.$fversion";
        $res .= "</td></tr>";
    }

    if ($pages = (int)$md["document:pages"])
        $res .= '<tr><td>'.$context->translate("Pages").":</td><td>$pages</td></tr>";

    if ($version = (int)$md["document:version"]) {
        $res .= '<tr><td>'.$context->translate("Version").":</td><td>$version";
        if ($revision = $md["document:revision"])
            $res .= "&nbsp;$revision";
        $res .= "</td></tr>";
    }
    return $res;
}

function formatImage($context, $md, &$link)
{
    $res = "";

    if ($title = $md["image:title"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }

    if ($artist = $md["image:artist"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Artist").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($artist)."'>".htmlentities($artist, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }

    if ($desc = $md["image:description"])
        $res .= '<tr><td>'.$context->translate("Description").":</td><td>".htmlentities($desc)."</td></tr>";

    if (($width = $md["image:width"]) && ($height = $md["image:height"]))
        $res .= '<tr><td>'.$context->translate("Size").":</td><td>{$width}x$height</td></tr>";

    if ($colors = (int)$md["image:colors"])
         $res .= '<tr><td>'.$context->translate("Colors").":</td><td>$colors</td></tr>";

    return $res;
}

function formatVideo($context, $md, &$link)
{
    $res = "";

    if ($title = $md["video:title"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a>";

        if (($len = $md["video:minutes"]*60) || ($len = $md["video:length"]))
            $res .= '&nbsp;('.formatLength($len).")";
        $res .= '</td></tr>';
    } else {
        if (($len = $md["video:minutes"]*60) || ($len = $md["video:length"]))
            $res .= '<tr><td>'.$context->translate("Length").':</td><td>'.formatLength($len)."</td></tr>";
    }
    if ($artist = $md["video:artist"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Artist").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($artist)."'>".htmlentities($artist, ENT_QUOTES, "UTF-8")."</a></td></tr>";
    }
    if (($width = $md["video:width"]) && ($height = $md["video:height"]))
        $res .= '<tr><td>'.$context->translate("Size").":</td><td>{$width}x$height</td></tr>";

    if ($fps = (int)$md["video:framerate"]) {
         $res .= '<tr><td>'.$context->translate("Quality").":</td><td>$fps fps";
         if ($codec = $md["video:codec"]) $res .= ' '.htmlentities($codec, ENT_QUOTES, "UTF-8");
         $res .= '</td></tr>';
    }
    return $res;
}

function formatSoftware($context, $md, &$link)
{
    $res = "";

    if ($title = $md["application:title"]) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a>";

        if ($version = $md["application:version"])
            $res .= "&nbsp;$version";
        $res .= '</td></tr>';
    }

    if ($fversion = $md["application:fileversion"])
        $res .= '<tr><td>'.$context->translate("Version").":</td><td>$fversion</a></td></tr>";

    if ($os = $md["application:os"])
         $res .= '<tr><td>'.$context->translate("OS").":</td><td>$os</td></tr>";

    return $res;
}

function formatArchive($context, $md, &$link)
{
    $res = "";
    if (($title = $md["archive:title"]) || ($title = $md["archive:name"])) {
        $link = true;
        $res .= '<tr><td>'.$context->translate("Title").":</td><td><a href='/{$context->lang}/search/?q=".urlencode($title)."'>".htmlentities($title, ENT_QUOTES, "UTF-8")."</a>";
    }
    if ($files = $md["archive:files"])
        $res .= '<tr><td>'.$context->translate("Files").":</td><td>".htmlentities($files, ENT_QUOTES, "UTF-8")."</td></tr>";
    if ($folders = $md["archive:folders"])
        $res .= '<tr><td>'.$context->translate("Folders").":</td><td>".htmlentities($folders, ENT_QUOTES, "UTF-8")."</td></tr>";
    if ($usize = $md["archive:unpackedsize"])
        $res .= '<tr><td>'.$context->translate("Unpacked size").":</td><td>".formatSize($usize)."</td></tr>";

    return $res;
}

 function formatSize($bytes)
    {
        $size = $bytes / 1024;
        if($size < 1024)
        {
            $size = number_format($size, 2);
            $size .= '&nbsp;KB';
        }
        else
        {
            if ($size / 1024 < 1024)
            {
                $size = number_format($size / 1024, 2);
                $size .= '&nbsp;MB';
            }
            else if ($size / 1024 / 1024 < 1024)
            {
                $size = number_format($size / 1024 / 1024, 2);
                $size .= '&nbsp;GB';
            }
        }
        return $size;
    }


function convertS2String($time) {
  $mins = floor($time / 60);
  $secs = floatval(($time % 60) / 100);
  $time = $mins+$secs.' min.';
  return $time;

}

foreach ($this->sources as $key => $val) {
        $t = $val['Type'];
        unset($mlinkadd2);
        $separateSources = false;

        switch ($t)
        {
            case 1: //GNUTELLA
                $tip = "Gnutella";
                $source = "gnutella";
                $mlinkadd = "&xt=urn:sha1:".$val['Uri'];
                break;
            case 2: //ED2K
                $tip = "ED2K";
                $source = "ed2k";
                $link = "ed2k://|file|".encodeFilename($this->filename['Filename'])."|".$this->file['Size']."|".$val['Uri']."|/";
                $mlinkadd2 = "&xt=urn:ed2k:".$val['Uri'];
                break;
            case 3: // TORRENT
                $tip = "Torrent";
                $source = "torrent";
                $link = $val['Uri'];
                $separateSources = true;
                break;
            case 5: //TIGER HASH
                $tip = "Gnutella";
                $source = "gnutella";
                $mlinkadd = "&xt=urn:tiger:".$val['Uri'];
                break;
            case 6: //MD5 HASH
                $tip = "Gnutella";
                $source = "gnutella";
                $mlinkadd = "&xt=urn:md5:".$val['Uri'];
                break;
            case 7: //BTH HASH
                $tip = "Torrent&nbsp;MagnetLink";
                $source = "tmagnet";
                if (($size=$this->file['Size'])>0) $size = "xl=".$this->file['Size']."&"; else $size = "";
                $link = "magnet:?{$size}dn=".encodeFilename($this->filename['Filename'])."&xt=urn:btih:".$val['Uri'];
                $mlinkadd2 = "&xt=urn:btih:".$val['Uri'];
                break;
            case 4: // JAMENDO
            case 8: // WEB
            case 10: // MU
            case 11: // RS
                $tip = "Web";
                $source = "web";
                $link = $val['Uri'];
                $separateSources = true;
                break;
            case 9: // FTP
                $tip = "FTP";
                $source = "ftp";
                $link = $val['Uri'];
                $separateSources = true;
                break;
            default:
                continue;
                break;
        }

        if ($source=="gnutella")
        {
            $rlink = $srcs['gnutella']['rlink'];
            if ($rlink)
                $mlink = $rlink.$mlinkadd;
            else {
    		if (($size=$this->file['Size'])>0) $size = "xl=".$this->file['Size']."&"; else $size = "";
                $mlink = "magnet:?{$size}dn=".encodeFilename($this->filename['Filename']).$mlinkadd;
	    }
            $link = $mlink;
        } elseif (isset($mlinkadd2))
        {
            $srcs['gnutella']['flink'] .= $mlinkadd2;
        }

        $srcs[$source]['link'] = htmlentities($link, ENT_QUOTES, "UTF-8");
        $srcs[$source]['rlink'] = $link;
        $srcs[$source]['tip'] = $tip;
        $srcs[$source]['count'] += $val['MaxSources'];
        if ($separateSources)
        {
            $srcs[$source]['links'][] = $link;
        }
}
foreach ($this->metadata as $key => $val)
{
    if (($val['KeyMD']=='torrent:trackers') || ($val['KeyMD']=='torrent:tracker'))
    {
        foreach (explode(' ', $val['ValueMD']) as $tr)
        {
            if ($srcs['gnutella']['link']) {
                $srcs['gnutella']['rlink'] .= '&tr='.urlencode($tr);
                $srcs['gnutella']['link'] = htmlentities($srcs['gnutella']['rlink'], ENT_QUOTES, "UTF-8");
            } else {
                $srcs['tmagnet']['rlink'] .= '&tr='.$tr;
                $srcs['tmagnet']['link'] = htmlentities($srcs['tmagnet']['rlink'], ENT_QUOTES, "UTF-8");
                $srcs['tmagnet']['has_trackers'] = true;
            }
        }
    } else {
        $md[$val['KeyMD']] = $val['ValueMD'];
    }
}
foreach (array('w'=>'web', 'f'=>'ftp', 't'=>'torrent', 't2'=>'tmagnet', 'g'=>'gnutella', 'e'=>'ed2k') as $srci=>$srcLink)
{
    if ($srcs[$srcLink]['link']) {
        if (!$srcLinkChoosen) $srcLinkChoosen = $srcLink;
        if (strstr($this->qs['src'], $srci[0]))
        {
            if ($srcLink!='tmagnet' || $srcs['tmagnet']['has_trackers'])
            {
                $srcLinkChoosen = $srcLink;
                break;
            }
        }
    }
}
$srcLink = $srcLinkChoosen;

global $content;
if ($this->qs['type'])
{
    $ctype = $this->qs['type'];
} else {
    try {
        $ctype = $content['assoc'][$this->file["ContentType"]];
    } 
    catch (Exception $ex) {}
}
if (!$ctype)
{
    try {
        $ctype = $content['extAssoc'][$this->filename["Extension"]];
    }
    catch (Exception $ex) {}
}
$ctype = strtolower($ctype);

//add meta to file related (better seo)
$this->headMeta()->appendName('description', 'download, '.$ctype.', '.$this->filename['Filename']);
$this->headMeta()->appendName('keywords',  'download, '.$ctype.', '.$this->filename['Filename']);
?>
<div id="container_search">
    <h1>
        <a href="/" ><img  src="<?=STATIC_PATH;?>/images/foofind_search.gif" alt="File search engine - foofind.com" title="File search engine - foofind.com" /></a>
    </h1>
    <?=$this->form; ?>
    <?if ($this->qs['q']):?>
    <div class="contentype">
        <a class="<?=(preg_match("/^$/",  $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= ''.$this->qs(array(), array('type'=>1, 'page'=>1)) ?>" ><?=$this->translate('All');?></a>
        <a class="<?=(preg_match("/^Audio$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Audio'), array('page'=>1)) ?>" ><?=$this->translate('Audio');?></a>
        <a class="<?=(preg_match("/^Video$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Video'), array('page'=>1)) ?>" ><?=$this->translate('Video');?></a>
        <a class="<?=(preg_match("/^Image$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Image'), array('page'=>1)) ?>" ><?=$this->translate('Image');?></a>
        <a class="<?=(preg_match("/^Document$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Document'), array('page'=>1)) ?>" ><?=$this->translate('Document');?></a>
        <a class="<?=(preg_match("/^Software$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Software'), array('page'=>1)) ?>" ><?=$this->translate('Software');?></a>
        <a class="<?=(preg_match("/^Archive$/", $this->qs['type']))?"actual":""?>" href="/<?=$this->lang?>/search/<?= $this->qs(array('type'=>'Archive'), array('page'=>1)) ?>" ><?=$this->translate('Archive');?></a>
    </div>
    <?endif?>
    <hr />
<?
if (count ( $this->mensajes ) > 0) {
	echo '<div class="success">';
	foreach ( $this->mensajes as $msg ) {
		echo $msg . '<br>';
	}
	echo '</div>';
}
?>

    <div class="wrap_download">
    <div class="file_download">
        <div class="file_download_vote <?=$this->myvote?>"><a href="#" rel="superbox[ajax][/<?=$this->lang?>/auth/login/source/vote.foo]" type="1" class="vote_up"><div></div><?=$this->translate('I like it!')?><br/><span>(<?=$this->votes['pos']?>)</span></a>&nbsp;<a href="#" rel="superbox[ajax][/<?=$this->lang?>/auth/login/source/vote.foo]" type="2" class="vote_down"><div></div><?=$this->translate('Booo!')?><br/><span>(<?=$this->votes['neg']?>)</span></a></div>
        <h2><?=$this->filename['Filename'];?></h2>
        
        <div class="top_download">
        <div class="download_button">
            <img alt="" src="<?=STATIC_PATH;?>/images/icons/content_<?=$ctype ?>.gif" /><br />
            <a title="<?=$this->translate('Download')?>" class="superlarge magenta awesome" href="<?=$srcs[$srcLink]['link'].$srcs[$srcLink]['flink']?>"><?=$this->translate('Download').($this->file_size<1 ? '':' ('.$this->file_size.')');?></a>
         </div>
        <div class="download_file_metadata"><?php showMetadata($this, $ctype, $this->filename['Filename'], $this->filename['Extension'], $md) ?></div>
       </div>

       <?php if ($this->sources): ?>
        <div class="dowload_file_sources">   
                    <? foreach ($srcs as $key => $val):
                        $links = null;
                        if ($val['links']) {
                            $links = $val['links'];
                            $multiple = true;
                        }
                        else {
                            if ($val['link']) $links = array($val['link']);
                            $multiple = false;
                        }
                        ?>
                        <div class="download_source" >
                        <?php
                        $i = 0;
                        foreach ($links as $link):
                             $i+=1;
                             if ($i>5) break;?>
                            <?='<input onClick="javascript:this.focus();this.select();" type="text"  value="'.$link.'" />'; ?>
                            <div style='background:url(<?=STATIC_PATH;?>/images/icons/<?=$key ?>_download.gif) left 0px no-repeat'><a title="<?=$link ?>" href="<?=$link ?>">
                            <? echo ucfirst ( $val['tip'] );
                                if (!$multiple && $val['count']>1) echo ' <span>'.$val['count'].' '.$this->translate('sources').'</span>';?>
                            </a></div>
                 <?php  endforeach; ?>
        </div>
           <?php endforeach; ?>
        </div>
       <?php endif; ?>

        <? if ($this->lang == 'en') $langcode = 1;
             if ($this->lang == 'es') $langcode = 2;
        ?>

        <div class="sharelinks"><?=$this->translate('Share this:');?>
            <a href="http://www.facebook.com/share.php?u=http://foof.in/<?=$langcode;?>/<?=dechex($this->file['IdFile'] );?>">
                <img alt="<?=$this->translate('share on facebook');?>" src="<?=STATIC_PATH;?>/images/icons/ico_facebook.gif" border = "0"/></a>
                <a href="mailto:?subject=<?=$this->filename['Filename'];?>&body=http://foof.in/<?=$langcode;?>/<?=dechex($this->file['IdFile']);?>">
                <img alt="<?=$this->translate('send by email');?>" src="<?=STATIC_PATH;?>/images/icons/ico_email_link.png" border = "0"/></a>
                <a href="http://twitter.com/home?status=http://foof.in/<?=$langcode;?>/<?=dechex($this->file['IdFile'] );?>">
                <img alt="<?=$this->translate('share on twitter');?>" src="<?=STATIC_PATH;?>/images/icons/ico_twitter.png" border = "0"/></a>
        </div>

        <div class="comments">
<? if (count($this->comments)>0 || $this->isAuth): ?>
        <?php echo $this->paginationControl($this->paginator, 'Sliding', 'paginator_md.phtml'); ?>
        <img src="<?=STATIC_PATH;?>/images/baloon.gif"/><h4><?=$this->translate('Your comments')?></h4>
<? endif;?>

<? if ($this->comments): ?>

       <?php
            $this->comments_refs = array();
            $this->count = count($this->comments);
            $i = $this->count + 1 - ($this->paginator->getCurrentPageNumber()-1)*$this->paginator->getItemCountPerPage();
            foreach ($this->paginator as $key => $val):
                $i--; ?>
        <div class="comment">
           <div class="file_comment_number"><a name="c<?=$i?>" href="?page=<?=$this->paginator->getCurrentPageNumber()?>#c<?=$i?>">#<?=$i?></a></div>
           <div class="file_comment_vote small <? switch($val['myvote']) {case 1: echo 'upactive'; break; case 2: echo 'downactive'; break;}?>" idcomment="<?=$val['IdComment']?>"><a href="#" rel="superbox[ajax][/<?=$this->lang?>/auth/login/source/vote.foo]" type="1" class="vote_up"><div></div><span><?=0+$val['pos']?></span></a>&nbsp;<a href="#" rel="superbox[ajax][/<?=$this->lang?>/auth/login/source/vote.foo]" type="2" class="vote_down"><div></div><span><?=0-$val['neg']?></span></a></div>
           <div id="c<?=$i?>"><?= $this->format_comment($val['text']); ?></div>
           <div class="file_comment_nick"><a href="/<?=$this->lang ?>/profile/<?=$this->escape($val['username']) ?>"><?=$val['username'] ?></a> - <? echo $this->show_date_span($val['date']); if ($val['location']!=null) echo  " ". $this->translate("from") ." ". $val['location']; ?></div>
        </div>

        <?php endforeach; ?>
        <script>
            var tooltips = [];

        <?php foreach ($this->comments_refs as $val):
                    $comment = $this->comments[$this->count-$val];
                    echo "tooltips[$val] = '<b>{$comment['username']}: </b>".$this->format_comment($comment['text'])."';";
              endforeach;?>

            $('.ttlink').tooltip({
                track: true,
                delay: 0,
                showURL: false,
                bodyHandler: function() { return tooltips[$(this).attr("tooltip")]; },
                fade: 250
            });

<?php   if ($this->isAuth): ?>
            $('.file_comment_vote a').click(function(event)
            {
                event.preventDefault();
                $.ajax({dataType:"json",
                    url: "/<?=$this->lang?>/vote/comment/"+$(this).parent().attr('idcomment')+"/"+$(this).attr('type'),
                    context: $(this),
                    success: function(data){
                        parent = this.context.parent();
                        if (this.context.attr('type')=='1') {
                            parent.addClass("upactive");
                            parent.removeClass("downactive");
                        }
                        else
                        {
                            parent.addClass("downactive");
                            parent.removeClass("upactive");
                        }


                        votes = [0,0];
                        for (vote in data) votes[data[vote].VoteType-1] = data[vote].c;

                        counter = $(".vote_up span", parent).text(votes[0]);
                        counter = $(".vote_down span", parent).text(-votes[1]);
                    }
                });
            });

            $('.file_download_vote a').click(function(event)
            {
                event.preventDefault();
                $.ajax({dataType:"json", 
                        url: "/<?=$this->lang?>/vote/file/<?=$this->file['IdFile']?>/"+$(this).attr('type')+"/idfilename/<?=$this->filename['IdFilename']?>",
                        context: $(this),
                        success: function(data){

                            parent = this.context.parent();
                            if (this.context.attr('type')=='1') {
                                parent.addClass("upactive");
                                parent.removeClass("downactive");
                            }
                            else
                            {
                                parent.addClass("downactive");
                                parent.removeClass("upactive");
                            }


                            votes = [0,0];
                            for (vote in data) votes[data[vote].VoteType-1] = data[vote].c;
                            
                            counter = $(".vote_up span", parent).text('('+votes[0]+')');
                            counter = $(".vote_down span", parent).text('('+-votes[1]+')');
                        }
                });
            });
<? else: ?>
            $(document).ready(function(){$.superbox();} );
            $.superbox.settings = {
                boxWidth: 400,
                boxHeight: 320,
                overlayOpacity: .4, // Background opaqueness
                loadTxt: "<?=$this->translate("Loading...")?>",
                closeTxt: "<?=$this->translate("Close")?>",
                prevTxt: "<?=$this->translate("Previous")?>",
                nextTxt: "<?=$this->translate("Next")?>"
            };
<?php endif;?>

        </script>

<?php endif;?>
    <?php echo $this->paginationControl($this->paginator, 'Sliding', 'paginator_md.phtml'); ?>
    <div class="comment_form"><?=$this->createcomment?></div>

    </div>
    </div>

    <div class="download_more_info">
        <h3><?=$this->translate('How to download?'); ?></h3>
        <p><?=$this->translate('DownloadExplanation'); ?></p>
        <p><img title="eDonkey, eMule, MLDonkey, aMule" alt="eDonkey, eMule, MLDonkey, aMule"  src="<?=STATIC_PATH;?>/images/icons/ed2k.gif" /> eMule, MLDonkey, aMule.</p>
        <p><img title="Gnutella, Frostwire,Limewire, Shareaza, Phex" alt="Gnutella, Frostwire, Limewire, Shareaza, Phex"  src="<?=STATIC_PATH;?>/images/icons/gnutella.gif" /> Limewire, Shareaza, Phex.</p>
        <p><img title="Torrent, Vuze, µTorrent, Transmission" alt="Torrent, Vuze, µTorrent, Transmission"  src="<?=STATIC_PATH;?>/images/icons/torrent.gif" /> µTorrent, Transmission.</p>
    </div>


</div>
</div>
